<?php

namespace App\Models\Project;

use App\Models\UserRole;
use Illuminate\Database\Eloquent\SoftDeletes;

class Progress extends Base
{
    use SoftDeletes;

    protected $table = 'pm_progresses';

    protected $fillable = [
        'stage',
        'name',
        'need_approve',
        'approve_type',
        'need_add_charge',
        //  'need_finance_approve',
        'payment_term_id',
        'sort',
//        'approve_roles',
    ];

    const STAGE_COMMUNICATE = 10;
    const STAGE_PLAN = 20;
    const STAGE_IMPLEMENT = 30;
    const STAGE_FINISH = 40;
    const STAGE_MAP = [
        self::STAGE_COMMUNICATE => ['name' => '沟通',],
        self::STAGE_PLAN => ['name' => '计划',],
        self::STAGE_IMPLEMENT => ['name' => '实施',],
        self::STAGE_FINISH => ['name' => '完结',],
    ];


    const WAIT_APPROVAL = '待审批';
    const APPROVAL_RESULT_PASS = '通过';
    const APPROVAL_RESULT_REJECT = '驳回';
    const APPROVAL_RESULT_TURN = '转批';
    const APPROVAL_RESULT_DELAY = '延期';
    const APPROVAL_RESULT_PAUSE = '暂停';
    const APPROVAL_RESULT_RESULTS = [
        self::APPROVAL_RESULT_PASS => ['name' => '通过'],
        self::APPROVAL_RESULT_REJECT => ['name' => '驳回'],
        self::APPROVAL_RESULT_TURN => ['name' => '转批'],
        self::APPROVAL_RESULT_DELAY => ['name' => '延期'],
        self::APPROVAL_RESULT_PAUSE => ['name' => '暂停'],
    ];

//    const APPROVE_TYPE_NOT = 'not';
    const APPROVE_TYPE_NORMAL = 'normal';
    const APPROVE_TYPE_PLAN = 'plan';
    const APPROVE_TYPE_REVIEW_MEETING = 'review_meeting';
    const APPROVE_TYPE_INTERNAL_EVALUATION = 'internal_evaluation';

    const APPROVE_TYPE_MAP = [
//        self::APPROVE_TYPE_NOT => ['name' => '不用审批',],
        self::APPROVE_TYPE_NORMAL => ['name' => '普通审批',],
        self::APPROVE_TYPE_PLAN => ['name' => '规划审批',],
        self::APPROVE_TYPE_REVIEW_MEETING => ['name' => '评审会结论',],
        self::APPROVE_TYPE_INTERNAL_EVALUATION => ['name' => '内部评价',],
    ];

    public function approveRole()
    {
        return $this->belongsToMany(UserRole::class, 'pm_progress_approve_role', 'role_id', 'progress_id');
    }
}
